package com.manage.server.controller.admin;

import com.manage.dto.UserDTO;
import com.manage.dto.add.UserAddDTO;
import com.manage.dto.update.UserUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.UserService;
import com.manage.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public Result add(@RequestBody UserAddDTO userAddDTO) {
        userService.save(userAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        userService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody UserUpdateDTO userUpdateDTO) {
        userService.updateById(userUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param userDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<UserVO> findUser(@RequestBody UserDTO userDTO) {
        PageResult<UserVO> userByPage = userService.findUserByPage(userDTO);
        System.out.println(userByPage);
        return userByPage;
    }
}